package com.agriculture.data_demo.repository;

import com.agriculture.data_demo.entity.sys.PigEnvEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

/**
 * @author morningbear
 * @date 20.10.7
 */
@Repository
public interface PigEnvRepository extends JpaRepository<PigEnvEntity, Integer> {

    @Query(value = "select * from pig_env", nativeQuery = true)
    Page<PigEnvEntity> findAll(PageRequest of);

    /**
     *
     * @param fence 猪舍
     * @return 根据猪舍类型查询
     */
    @Query(value = "select * from pig_env where fence = ?1", nativeQuery = true)
    Page<PigEnvEntity> findByFence(String fence, Pageable pageable);

    /**
     *
     * @param temp 温度
     * @return 找出温度高于平均值的栏位
     */
    @Query(value = "select * from pig_env where temp > (select avg (temp) from pig_env)", nativeQuery = true)
    Page<PigEnvEntity> findByTemperature(Double temp, Pageable pageable);
}
